DBLookupComboBox

Otázka od: David Liska

25. 11. 2003 16:00

Ahoj,
potreboval bych komponentu jako je DBLookupComboBox, ale s tim aby to
uzivateli predepisovalo znamy text (napise par pismen a ma to nabizet zbytek
z nejakeho lookup datasetu).
Nemate nekdo neco takoveho?

Predem diky, David





----------
* www.inMail.sk - Vasa emailova adresa na cely zivot ZDARMA
* Mail neobsahuje virusy. Zkontrolovane antivirusom NOD32 (www.eset.sk)
* www.SlovakNET.sk - profesionalny webhosting, domena .SK ZADARMO
* Zoner Media Explorer 5 - stiahnite si pomocnika pre digitalnu fotografiu
(zme.zoner.sk)

Odpovedá: LUKES Vaclav

25. 11. 2003 16:25

Podivej se na JEDI...
V.



-----Original Message-----
From: David Liska [mailto:konference@thsoft.cz]
Sent: Tuesday, November 25, 2003 3:47 PM
To: delphi-l@clexpert.cz
Subject: DBLookupComboBox


Ahoj,
potreboval bych komponentu jako je DBLookupComboBox, ale s tim aby to
uzivateli predepisovalo znamy text (napise par pismen a ma to nabizet zbytek
z nejakeho lookup datasetu).
Nemate nekdo neco takoveho?

Predem diky, David







----------
* www.inMail.sk - Vasa emailova adresa na cely zivot ZDARMA
* Mail neobsahuje virusy. Zkontrolovane antivirusom NOD32 (www.eset.sk)
* www.SlovakNET.sk - profesionalny webhosting, domena .SK ZADARMO
* Zoner Media Explorer 5 - stiahnite si pomocnika pre digitalnu fotografiu
(zme.zoner.sk)

Odpovedá: Jiri Virt

25. 11. 2003 16:14

unit JVDBLookupComboSearch;
interface
uses
  SysUtils, WinTypes,WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, DBLookup, DB, DBTables;

type
  JVDBLookupCombo = class(TDBLookupCombo)
 private
  CanChange: Boolean;
  FieldLength: Integer;
  LimitedToList: boolean;
  HadWildCard: Boolean;
  Ordered: Boolean;
  Entered: Boolean;
  SearchField: TField;
  SearchType SuperSlow,Slow,Fast);
 protected
  procedure DoEnter; override;
  procedure DoExit; override;
  procedure Change; override;
 procedure KeyDown(var Key: Word; Shift: TShiftState); override;
 public
  constructor Create(AOwner: TComponent); override;
  procedure FindRow;
 published
  property LimitTolist: Boolean read LimitedToList write LimitedToList
default False;
  property IsOrdered: boolean read Ordered write Ordered default False;
end;

procedure Register;
procedure FindCarefully(Table: TDataSet;SearchField: TField; const
SubString: String);
procedure FindContaining(Table: TDataSet ;SearchField: TField; const
SubString: String; Down: Boolean);
{procedure FindQuick(Table: TDataSet;Field: String; const SubString:
String);
procedure SearchQuick(const DataSet: TDataSet;const SearchField:
TField; const SubString: String 1024: integer);}
implementation


procedure FindCarefully(Table: TDataSet;SearchField: TField; const
SubString: String);
begin
try
 with Table do
  begin
  DisableControls;
  if CompareText(SubString,(SearchField.AsString))>0 then
   while (CompareText(SubString,(SearchField.AsString))>0) AND (not EOF) do
Next
  else
   begin
    while (CompareText(SubString,(SearchField.AsString))<0) AND (not BOF) do
Prior;
   if (CompareText(SubString,(SearchField.AsString))>0) then Next;
   end;
  end;
 finally
  Table.EnableControls;
 end;
end;

procedure FindContaining(Table: TDataSet;SearchField: TField; const
SubString: String; Down: Boolean);
var
  CapSubString: String;
begin
try
  CapSubString:=UpperCase(SubString);
  with Table do
   begin
    DisableControls;
    if Down then
     while ((Pos(CapSubString,UpperCase(SearchField.AsString))=0)AND (not
EOF)) do Next
    else
     while ((Pos(CapSubString,UpperCase(SearchField.AsString))=0)AND(not
BOF))do Prior;
    if EOF then First;
   end;
  finally
   Table.EnableControls;
  end;
end;

procedure JVDBLookupCombo.Change;
var
{ source: TDataSource;}
  CurrentValue: String; FirstChar: string[1];
begin
  inherited Change;
  if CanChange then
  begin
    try
      CanChange:=False;
      CurrentValue:=Text;
      FirstChar:= CurrentValue;
      if (FirstChar='*') or (FirstChar='%') then
       begin
        if HadWildCard=False or (FieldLength>Length(CurrentValue)) then
LookUpSource.DataSet.First;
        HadWildCard:=True;
        end
      else
       begin
        case SearchType of
          Superslow:
FindCarefully(LookUpSource.DataSet,SearchField,CurrentValue);
          Slow :
FindCarefully(LookUpSource.DataSet,SearchField,CurrentValue);
          Fast  LookUpSource.DataSet as
TTable).FindNearest([CurrentValue]);
        end;
      HadWildCard:=False;
     end;
    finally
      CanChange:=True;
      FieldLength:=Length(CurrentValue);
  end;
 end;
end;

constructor JVDBLookupCombo.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  CanChange:=False;
  LimitedToList:=False;
  HadWildCard:=False;
  FieldLength:=0;
  Ordered:=False;
  Entered:=False;
end;

procedure JVDBLookupCombo.DoEnter;
var
   Field, IndexField: String;
begin
 try
  DropDown;
  HadWildCard:=False;
  CanChange:=True;
  Entered:=True;
  if Pos(';',Lookupdisplay)>0 then
   Field:=Copy(Lookupdisplay,1,Pos(';',Lookupdisplay)-1)
  else Field:= Lookupdisplay;
  SearchField:=LookUpSource.DataSet.FindField(Field);
  IndexField:=Copy((LookUpSource.DataSet as
TTable).IndexFieldNames,1,length(Field));
  CanChange:=Assigned(SearchField);
  if (LookUpSource.DataSet is TTable) then
   if CompareText(Field,IndexField)=0 then
    SearchType:=Fast
   else
    if Ordered then SearchType:=Slow else SearchType:=SuperSlow
   else
    if Ordered then SearchType:=Slow else SearchType:=SuperSlow;
  DropDown;
  inherited DoEnter;
  Change;
  except
   SearchType:=SuperSlow;
 end;
end;

procedure JVDBLookupCombo.DoExit;
begin
  try
    if LimitedToList then
    begin
      {CanChange:=False;}
     with DataSource.DataSet do
      if (State=dsEdit) or (State=dsInsert) then
      begin
       Text:=SearchField.AsString;
      end;
   end;
  finally
   CloseUp;
   inherited DoExit;
  end;
end;

procedure JVDBLookupCombo.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
 VK_RETURN:begin
            if not (LookUpSource.DataSet.Locate(LookupField,Value,[])) then
             begin
              Key := 0;
              SetFocus;
             end else CloseUp;
           end;{VK_RETURN}
end; {case}
inherited KeyDown(Key,Shift);
end;

procedure JVDBLookupCombo.FindRow;
begin
if Entered then DoEnter else Change;
end;


procedure Register;
begin
RegisterComponents('JV', [JVDBLookupCombo]);
end;

end.

Spachal
Jiri Virt






----------
* www.inMail.sk - Vasa emailova adresa na cely zivot ZDARMA
* Mail neobsahuje virusy. Zkontrolovane antivirusom NOD32 (www.eset.sk)
* www.SlovakNET.sk - profesionalny webhosting, domena .SK ZADARMO
* Zoner Media Explorer 5 - stiahnite si pomocnika pre digitalnu fotografiu
(zme.zoner.sk)